#include "PowerPage.h"
#include "PowerMonitor.h"

#include "MachineDependents.h"


PowerPage::PowerPage(const int pageNum) : super(pageNum) {
        mpageSize = 2;

        mpControllers = &ExtendDeviceManagerSingleton::instance().getExtendDevices(ExtendDeviceEnum::POWER);
    }



void PowerPage::paint() {
    std::string content[4];

    resetStream();

    strStream << "powerMonitor" << std::right << std::setw(4) << pageNum;// << std::setw(3)
    content[0] = strStream.str();

    if (mpControllers->empty() ) {
        content[1] = ExtendDeviceEnum::NO_DEVICE.name;
    } else {
        ExtendDevicePtr extendDevicePtr = mpControllers->front().lock();
        if (nullptr == extendDevicePtr) {
            content[1] = ExtendDeviceEnum::NO_DEVICE.name;
        } else {

            PowerMonitor* pPowerMonitor = static_cast<PowerMonitor*> (&*extendDevicePtr);

            pPowerMonitor->updateInformation();
            if(0 == mmultiPageNo) {
                content[1].append("power:").append(pPowerMonitor->mkwh);//
                content[2].append("rtPwer:").append(pPowerMonitor->mpower);
                content[3].append("prGdFreq:").append(pPowerMonitor->mgridFrequency);
            } else {
                resetStream();
                pPowerMonitor->maPhase.toStringNoPort(strStream);
                content[0] = strStream.str();

                resetStream();
                pPowerMonitor->mbPhase.toStringNoPort(strStream);
                content[1] = strStream.str();

                resetStream();
                pPowerMonitor->mcPhase.toStringNoPort(strStream);
                content[2] = strStream.str();

                content[3].append("coeffic:").append(pPowerMonitor->mcoefficient);
            }
        }
    }
    screen.show(&content[0], &content[1], &content[2], &content[3]);
}
